package com.wxp.entity;

import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.modules.model.SimpleModel;


@Entity
@Table(name = "t_user")
public class User extends SimpleModel{

    @Id
    @Column(name = "USER_ID_", nullable = false, insertable = true, updatable = false)
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "com.modules.utils.IDGenerator")
    private String userId;
    
    
    //基本信息
    @Length(max=64)
    @Column(name="NAME_CODE_" ,nullable = true ,unique = true ,insertable = true ,updatable = true,length=64)
    private String nameCode;
    
    //基本信息
    @Length(max=64)
    @Column(name="NAME_" ,nullable = true ,unique = false ,insertable = true ,updatable = true,length=64)
    private String name;
    
    
    //真实姓名
    @Length(max=64)
    @Column(name="REAL_NAME_" ,nullable = true ,unique = false ,insertable = true ,updatable = true,length=64)
    private String realName;
    //别名
    @Length(max=64)
    @Column(name="NIKE_NAME_" ,nullable = true ,unique = false ,insertable = true ,updatable = true,length=64)
    private String nickName;

    @Column(name="AGE_" ,nullable = true ,unique = false ,insertable = true ,updatable = true)
    private Integer age;
    
    @Length(max=64)
    @Column(name="TELE_PHONE_" ,nullable = true ,unique = false ,insertable = true ,updatable = true,length=64)
    private String telePhone;

    @Length(max=128)
    @Column(name="PASSWORD_" ,nullable = true ,unique = false ,insertable = true ,updatable = true,length=128)
    private String password;
    
    @Length(max=2)
    @Column(name="SEX_" ,nullable = true ,unique = false ,insertable = true ,updatable = true,length=2)
    private String sex;

   
    //身份证好
    @Length(max=64)
    @Column(name="ID_CARD_" ,nullable = true ,unique = false ,insertable = true ,updatable = true,length=64)
    private String idCard;

    //邮箱
    @Length(max=64)
    @Column(name="EMAIL_" ,nullable = true ,unique = false ,insertable = true ,updatable = true,length=64)
    private String email;

    @Temporal(TemporalType.DATE)
    @Column(name = "BIRTHDATE_", unique = false, nullable = true, insertable = true, updatable = true)
    private Date birthdate;

    //地址
    //省市区=
    @Length(max=64)
    @Column(name="PROVINCE_" ,nullable = true ,unique = false ,insertable = true ,updatable = true,length=64)
    private String province;
    @Length(max=64)
    @Column(name="CITY_" ,nullable = true ,unique = false ,insertable = true ,updatable = true,length=64)
    private String city;
    @Length(max=64)
    @Column(name="COUNTY_" ,nullable = true ,unique = false ,insertable = true ,updatable = true,length=64)
    private String county;
    //详细地址
    @Length(max=128)
    @Column(name="ADDRESS_" ,nullable = true ,unique = false ,insertable = true ,updatable = true,length=128)
    private String address;

    //注册信息
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "REGISTER_TIME_", nullable = true ,unique = false ,insertable = true ,updatable = false,length=64)
    private Date registerTime;
    @Length(max=64)
    @Column(name="REGISTER_IP_" ,nullable = true ,unique = false ,insertable = true ,updatable = false,length=64)
    private String registerIp;
    
    //加密部分盐值
    @Length(max=64)
    @Column(name="SALT_" ,nullable = true ,unique = false ,insertable = true ,updatable = false,length=64)
    private String salt;
    
    @JsonIgnore
    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE},fetch = FetchType.EAGER)  
    @JoinTable(name = "T_USER_ROLE", joinColumns = {@JoinColumn(name ="USER_ID_" )}, inverseJoinColumns = { @JoinColumn(name = "ROLE_CODE_",insertable = false,updatable = false) })  
    private Set<Role> roles;  //角色集合,一个用户可以有多个角色  
    
    
   
	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getTelePhone() {
        return telePhone;
    }

    public void setTelePhone(String telePhone) {
        this.telePhone = telePhone;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }


    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Date getRegisterTime() {
        return registerTime;
    }

    public void setRegisterTime(Date registerTime) {
        this.registerTime = registerTime;
    }

    public String getRegisterIp() {
        return registerIp;
    }

    public void setRegisterIp(String registerIp) {
        this.registerIp = registerIp;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getIdCard() {
        return idCard;
    }

    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCounty() {
        return county;
    }

    public void setCounty(String county) {
        this.county = county;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    

    public Date getBirthdate() {
		return birthdate;
	}

	public void setBirthdate(Date birthdate) {
		this.birthdate = birthdate;
	}
	
	
	

	public String getNameCode() {
		return nameCode;
	}

	public void setNameCode(String nameCode) {
		this.nameCode = nameCode;
	}
	

	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}
	
	

	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
	
	
	

	

	@Override
    public boolean equals(Object obj) {
        if(obj instanceof User == false) return false;
        if(this == obj) return true;
        User other = (User)obj;
        return new EqualsBuilder()
                .append(getUserId(),other.getUserId())
                .isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder()
                .append(getUserId())
                .toHashCode();
    }

    
    
    
	@Override
	public String toString() {
		return "User [userId=" + userId + ", nameCode=" + nameCode + ", name=" + name + ", realName=" + realName
				+ ", nickName=" + nickName + ", age=" + age + ", telePhone=" + telePhone + ", password=" + password
				+ ", sex=" + sex + ", idCard=" + idCard + ", email=" + email + ", birthdate=" + birthdate
				+ ", province=" + province + ", city=" + city + ", county=" + county + ", address=" + address
				+ ", registerTime=" + registerTime + ", registerIp=" + registerIp + ", salt=" + salt + ", roles="
				+ roles + "]";
	}


    
}